
<html>
  <head>
    <meta http-equiv="Encoding" content="utf-8"/>
    <title>Validador de Datas - C&oacute;digo com Caf&eacute; - Programa&ccedil;&atilde;o e assuntos relacionados. Com caf&eacute;.</title>
    <script language="javascript" type="text/javascript">
      function fica_errado(element)
      {
        document.getElementById('dataval').style.color = "red";
        document.getElementById('dataval').innerHTML = "Data inv&aacute;lida!";
      }
      function fica_certo(element)
      {
        document.getElementById('dataval').style.color = "blue";
        document.getElementById('dataval').innerHTML = "Data v&aacute;lida!";
      }
      function valida_data(element) 
      {
          regex = /^((((0?[1-9]|1\d|2[0-8])\/(0?[1-9]|1[0-2]))|((29|30)\/(0?[13456789]|1[0-2]))|(31\/(0?[13578]|1[02])))\/((19|20)?\d\d))$|((29\/0?2\/)((19|20)?(0[48]|[2468][048]|[13579][26])|(20)?00))$/;
        
        resultado = regex.exec(element.value);
        if(!resultado)
        {
          fica_errado(element);
        }
        else
        {
          fica_certo(element);
        }
      }
    </script>
  </head>
  <body>
    <form name="teste" action="./" method="get" onsubmit="return false;">
      <label for="data">Data:</label>
      <input type="text" name="data" id="data" onkeyup="valida_data(this)" />
      <label style="color:red;" id="dataval" class="dataval""></label>
    </form>
  </body>
</html>